#define _CRT_SECURE_NO_WARNINGS 1

struct ListNode* removeElements(struct ListNode* head, int val)
{
    while (NULL != head && head->val == val)
    {
        head = head->next;
    }
    struct ListNode* curr = head;
    struct ListNode* prev = NULL;
    while (curr != NULL)
    {
        if (curr->val != val)
        {
            prev = curr;
        }
        else
        {
            prev->next = curr->next;
        }
        curr = curr->next;
    }
    return head;
}

struct ListNode* middleNode(struct ListNode* head)
{
    struct ListNode* fast = head;
    struct ListNode* slow = head;
    while (fast && fast->next)
    {
        slow = slow->next;
        fast = fast->next->next;
    }
    return slow;
}

struct ListNode* FindKthToTail(struct ListNode* pListHead, int k)
{
    struct ListNode* fast = pListHead;
    struct ListNode* slow = pListHead;
    while (k--)
    {
        if (fast == NULL)
            return NULL;
        fast = fast->next;
    }
    while (fast)
    {
        slow = slow->next;
        fast = fast->next;
    }
    return slow;
}